<?php
/**
 * 好友邀请
 *
 *
 *
 * @网店运维提供技术支持 授权请购买shopnc授权
 * @license    http://www.shopwwi.com
 * @link       交流群号：111731672
 */


defined('ByShopWWI') or exit('Access Invalid!');
class inviterControl extends BaseHomeControl{

    public function indexOp(){

        if ($_SESSION['is_login'] !== '1'){
            showDialog($message = '请登录后邀请', $url = urlLogin('login', 'index')); exit();
        }
		
        $invite_model= Model('member');
        $get_code=array();
        $get_code['user']= $_SESSION['member_name'];

        if(!$invite_model->selectCode($get_code)){
            $set_code=array();
            $set_code['user']= $_SESSION['member_name'];
            $set_code['code']= $_SESSION['member_id'];
            $invite_model->inviteCode($set_code);
        }

        $invite=$invite_model->selectCode(array('guest'=>$_SESSION['member_id']));

        $reg= urlMember('login','register',array('rg'=>$_SESSION['member_id']));
        $mb_invite= 'invite_'.$_SESSION['member_id']. '.png';
        $this->mb_invite($mb_invite);
        $invite_img= BASE_SITE_URL.DS.DIR_UPLOAD.DS.ATTACH_COMMON.DS.$mb_invite;
        Tpl::output('invite',$invite);
        Tpl::output('invite_img',$invite_img);
        Tpl::output('reg',$reg);
        Tpl::showpage('inviter');
    }

    /**
     * 生成二维码
     */
    public function mb_invite($invite) {
        $url = APP_SITE_URL.DS.'index.php?act=temp&op=register&rg='.$_SESSION['member_id'];
        require_once(BASE_RESOURCE_PATH.DS.'phpqrcode'.DS.'index.php');
        $PhpQRCode = new PhpQRCode();
        $PhpQRCode->set('pngTempDir',BASE_UPLOAD_PATH.DS.ATTACH_COMMON.DS);
        $PhpQRCode->set('date',$url);
        $PhpQRCode->set('pngTempName', $invite);
        $PhpQRCode->init();

     }


}
